<!DOCTYPE html>
<html>

<p id="demo">一个段落222</p>

<head>
<meta charset="utf-8">
</head>

<script>
function validateForm() {
    var x = document.forms["myForm"]["fname"].value
    if (x == null || x == "") {
        alert("请输入名字")
        return false
    }
    return true
}
</script>


<body>

    <!-- action="demo_form.php" -->
<form name="myForm" action="myScript.js" onsubmit="return validateForm()" method="post">
名字：
<!-- 如果表单字段 (fname) 的值为空, required 属性会阻止表单提交： -->
<input type="text" name="fname" required="required">
<input type="submit" value="提交">
</form>

</body>

</html>
